package com.northpool.operator.common.scene;

import cn.hutool.core.util.StrUtil;
import com.northpool.operator.annotation.InputParam;
import com.northpool.operator.annotation.InputParams;
import com.northpool.operator.annotation.OperatorInfo;
import com.northpool.operator.annotation.OutputParam;
import com.northpool.operator.annotation.OutputParams;
import com.northpool.operator.common.algorithm.OperatorTestBuild;
import com.northpool.operator.common.algorithm.TestParamBuilder;
import com.northpool.operator.param.ParamTool;
import com.northpool.operator.utils.StpOperatorHelper;

@OperatorInfo(
        ref = "sceneOutOperator",
        name = "结果输出",
        version = "数据ID",
        description = "用于对接不同的结果预览页面和结果获取"
)
@OutputParams({
        @OutputParam(ref = "dataId", name = "数据表ID", desc = "数据中心数据表ID"),
        @OutputParam(ref = "tableName", name = "数据表名称", desc = "数据表名称")
})
public class SceneDataIdOutOperator extends StpOperatorHelper {

    @InputParams({
            @InputParam(ref = "dataId", name = "数据ID", desc = "数据中心数据表ID", required = true),
            @InputParam(ref = "tableName", name = "数据表名称", desc = "数据表名称，如: public.table", required = true),
    })
    public SceneDataIdOutOperator() {
    }

    public static void main(String[] args) throws Exception {
        OperatorTestBuild.execute(SceneDataIdOutOperator.class, TestParamBuilder.aBuilder()
                .param("dataId", "test")
                .param("tableName", "table")
                .build());
    }

    @Override
    public void execute(ParamTool paramTool) throws Exception {
        String dataId = paramTool.getStr("dataId");
        String tableName = paramTool.getStr("tableName");
        if (StrUtil.isBlank(dataId)) {
            throw new RuntimeException("参数数据ID不能为空");
        }
        if (StrUtil.isBlank(tableName)) {
            throw new RuntimeException("参数表名称不能为空");
        }
        this.result("dataId", dataId);
        this.result("tableName", tableName);
    }
}
